// ----------------------------------
// projects/c++/collatz/TestCollatz.h
// Copyright (C) 2009
// Glenn P. Downing
// ----------------------------------

#ifndef TestPrimes_h
#define TestPrimes_h

// --------
// includes
// --------

#include <sstream> // istringtstream, ostringstream
#include <string>  // ==

#include "cppunit/TestFixture.h"             // TestFixture
#include "cppunit/extensions/HelperMacros.h" // CPPUNIT_TEST, CPPUNIT_TEST_SUITE, CPPUNIT_TEST_SUITE_END

// -----------
// TestCollatz
// -----------

struct TestPrimes : CppUnit::TestFixture {
    // ----
    // read
    // ----

    void test_read () {
        std::istringstream in("2\n");
        const bool b = read(in);
        CPPUNIT_ASSERT(b == true);
        CPPUNIT_ASSERT(v ==    2);}

    // ----
    // eval
    // ----

    void test_eval_1 () {
        v =  2;
        eval();
        CPPUNIT_ASSERT(!valid);}

    void test_eval_2 () {
        v = 100;
        i = 0;
        j = 0;
        k = 0;
        l = 0;
        eval();
        CPPUNIT_ASSERT((i + j + k + l) == v);}

    void test_eval_3 () {
        v =   200;
        i = 0;
        j = 0;
        k = 0;
        l = 0;
        eval();
        CPPUNIT_ASSERT((i + j + k + l) == v);}

    void test_eval_4 () {
        v =   8;
        i = 0;
        j = 0;
        k = 0;
        l = 0;
        eval();
        CPPUNIT_ASSERT((i + j + k + l) == v);}

    void test_eval_5() {
        v =   883209;
        i = 0;
        j = 0;
        k = 0;
        l = 0;
        eval();
        CPPUNIT_ASSERT((i + j + k + l) == v);}

    void test_eval_6(){
        v =   91629;
        i = 0;
        j = 0;
        k = 0;
        l = 0;
        eval();
        CPPUNIT_ASSERT( (i + j + k + l) == v);}

    void test_eval_7(){
        v =   20000;
        i = 0;
        j = 0;
        k = 0;
        l = 0;
        eval();
        CPPUNIT_ASSERT( (i + j + k + l) == v);}
    // -----
    // print
    // -----

    void test_print () {
        i = 2;
        j = 3;
        k = 5;
        l = 7;
        std::ostringstream out;
        print(out);
        CPPUNIT_ASSERT(out.str() == "2 3 5 7\n");}

    // -----
    // suite
    // -----

    CPPUNIT_TEST_SUITE(TestPrimes);
    CPPUNIT_TEST(test_read);
    CPPUNIT_TEST(test_eval_1);
    CPPUNIT_TEST(test_eval_2);
    CPPUNIT_TEST(test_eval_3);
    CPPUNIT_TEST(test_eval_4);
    CPPUNIT_TEST(test_eval_5);
    CPPUNIT_TEST(test_eval_6);
    CPPUNIT_TEST(test_eval_7);
    CPPUNIT_TEST(test_print);
    CPPUNIT_TEST_SUITE_END();};

#endif

